#!/bin/bash -e
# need cosmic info, gatk VariantType, annovar 

function info() {
echo Usage: `basename $0` in.vcf
exit 65
}

while getopts  ":i:b:p:" opts
do
        case  $opts  in
        i) interval=$OPTARG;;
		b) asemmbly=$OPTARG;;
		p) out_prefix=$OPTARG;;
		*) info;;
        esac
done
shift $(($OPTIND - 1))

if [ -z $1 ]; then info; fi


. $var

echo basic info 
cat $1 |grep -v '^##'|cut -f1-5,7 |sed '1s/\#CHROM\tPOS/CHROM\tGRCh37 POS/' >$out_prefix.vcf_basic.txt


# cat $1 |java -jar $snpsift extractField ../$1 "GEN[0].DP" > 1.dp.txt

echo custom made info 
# cat $1 |java -jar $snpsift extractField - "GEN[0].DP" af VariantType HOM HET STRAND Gene.refGene CDS Func.refGene ExonicFunc.refGene AAChange.refGene  |sed '1s/\#GEN\[0\]\.DP/DP/' >$out_prefix.some_info.txt


# cat $1 |java $j_mem -jar $snpsift extractField - "GEN[0].DP" "ANN[0].EFFECT" "ANN[0].IMPACT" af VariantType Gene.refGene CDS Func.refGene ExonicFunc.refGene AAChange.refGene  |sed '1s/\#GEN\[0\]\.DP/DP/' |sed '1s/ANN\[0\]\.//g' >$out_prefix.some_info.txt # only has a # at the beginning

cat $1 |java $j_mem -jar $snpsift extractField - "GEN[0].DP" "ANN[0].EFFECT" "ANN[0].IMPACT" af Gene.refGene CDS Func.refGene ExonicFunc.refGene AAChange.refGene  |sed '1s/\#GEN\[0\]\.DP/DP/' |sed '1s/ANN\[0\]\.//g' >$out_prefix.some_info.txt

file_size=`du -m $out_prefix.some_info.txt|cut -f1`
if test $file_size -gt 30; then

paste $out_prefix.vcf_basic.txt $out_prefix.some_info.txt > $out_prefix.simple_info.txt && rm $out_prefix.vcf_basic.txt $out_prefix.some_info.txt

zip $out_prefix.anno.info.txt.zip $out_prefix.simple_info.txt # no supprot zip *.zip -



else 

paste $out_prefix.vcf_basic.txt $out_prefix.some_info.txt > $out_prefix.simple_info.txt
tab2xls.pl $out_prefix.simple_info.txt $out_prefix.simple_info.xls

format_jxl.sh $out_prefix.simple_info.xls $out_prefix.anno.info.jxl.xls

rm $out_prefix.simple_info.xls $out_prefix.vcf_basic.txt $out_prefix.some_info.txt

fi

. $cmd_done